/**
 * author bianlongting
 * email 1137060420
 * date 2016-4-14
 * [description] 图片预览 兼容IE6
 */

;(function(){
	$.fn.extend({
		preview : function(options){
			//默认参数值
			var defaults = {
				show : null			//接收显示图片节点
			};
			var opts = $.extend({}, defaults, options);
			return this.each(function(){
				var o = opts;
				var parent = $(this);      //当前容器
				parent.change(function(){
			        var explorer = navigator.userAgent;
			        var imgSrc = $(this)[0].value;
			        if (explorer.indexOf('MSIE') >= 0) {	//非IE
			            if (!/\.(jpg|jpeg|png|JPG|PNG|JPEG)$/.test(imgSrc)) {
			                imgSrc = "";
			                return false;
			            }else{
			                o.show.attr("src",imgSrc);
			            }
			        }else{									//IE
			            if (!/\.(jpg|jpeg|png|JPG|PNG|JPEG)$/.test(imgSrc)) {
			                imgSrc = "";
			                return false;
			            }else{
			                var file = $(this)[0].files[0];
			                var url = URL.createObjectURL(file);
			                o.show.attr("src",url);
			            }
			        }
			    });
			})
			
		}
	})
})();